<template>
	<view>
		<van-card :num="item.goods_number" :price="item.goods_price" desc="描述信息" :title="item.goods_name"
			:thumb=" item.goods_small_logo " v-for="(item,index) in list" :key="index"
			:thumb-link="'/pages/detail/detail?id='+item.goods_id" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				obj: {
					cid: 0,
					pagenum: 1,
					pagesize: 8
				}
			};
		},
		onLoad(e) {
			console.log(e)
			this.obj.cid = e.id
			this.getlist()
		},
		methods: {
			getlist() {
				wx.request({
					url: 'https://api-hmugo-web.itheima.net/api/public/v1/goods/search?cid=' + this.obj.cid +
						"&pagenum=" + this.obj.pagenum + "&pagesize=" + this.obj.pagesize,
					method: 'GET',
					success: (res) => {
						console.log(res)
						this.list = [...this.list, ...res.data.message.goods]
						this.allpage = Math.ceil(res.data.message.total / this.obj.pagesize)
					}
				})
			},
			onReachBottom() {
				this.obj.pagenum += 1
				if (this.obj.pagenum < this.allpage) {
					this.getlist()
				}
			},
			async onPullDownRefresh() {
				this.obj.pagenum = 1
				await wx.stopPullDownRefresh()
			}
		}
	}
</script>

<style lang="scss">

</style>
